package LeetCode.month01.day30;

import java.util.HashMap;

public class No2024 {
    public static void main(String[] args) {
        System.out.println(maxConsecutiveAnswers("TTFTTTTTFT",1));
    }
    public static int maxConsecutiveAnswers(String answerKey, int k) {
        int n = answerKey.length();
        char[] c = answerKey.toCharArray();
        int left = 0;
        int res1 = 0;
        int num = 0;
        for (int i = 0; i < n; i++) {
            if(c[i]=='T') num++;
            while(num>k){
                if(c[left]=='T') num--;
                left++;
            }
            res1 = Math.max(res1,i-left+1);
        }
        res1 = Math.max(res1,n-left);
        int res = 0;
        left = 0;
        num=0;
        for (int i = 0; i < n; i++) {
            if(c[i]=='F') num++;
            while(num>k){
                if(c[left]=='F') num--;
                left++;
            }
            res = Math.max(res,i-left+1);
        }
        res = Math.max(res,n-left);
        return Math.max(res,res1);
    }
}
